import bg.cookbook.SlideCreator;
import bg.cookbook.SlideEvent;

import flash.display.StageDisplayState;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.ui.Mouse;

import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import mx.events.FlexEvent;

private var v:Vector.<String>;

private var currentSlide:SlideCreator;




		

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
	FlexGlobals.topLevelApplication.addEventListener(KeyboardEvent.KEY_UP, keyDownESC);
	v=new Vector.<String>();
	
	this.addEventListener(SlideEvent.SELECTED, changeSlideCreator);
	
	
}
public function sSlideshow(event:Event):void
{	
	this.stage.displayState = StageDisplayState.FULL_SCREEN;
	this.currentState='slideshowMode'; 
	bar.deselectAll(null,currentSlide);
	im.listOfSlides=bar.getAllSlides();
	currentSlide=null;
}

private function onClose(event:CloseEvent):void
{
	Mouse.show();
	if(this.currentState != 'editMode')
	{
		im.stopSlideshow();
		bar.addSlides(im.listOfSlides);
	}
	this.currentState = 'editMode';
}

protected function keyDownESC(event:KeyboardEvent):void
{
	if(event.keyCode==Keyboard.ESCAPE)
	{
		trace("asd2");
		onClose(null);
	}
}

protected function changeSlideCreator(event:SlideEvent):void
{
	var oldSC:SlideCreator = currentSlide;
	
	if(currentSlide != event.locker.slideCreator)
	{

		hldr.removeAllElements();
		hldr.addElement(event.locker.slideCreator);
		event.locker.slideCreator.scaleX = 1;
		event.locker.slideCreator.scaleY = 1;
		currentSlide = event.locker.slideCreator;
	}
	
	bar.deselectAll(event.locker,oldSC);
}
